package samse.app.ebook;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class BookShelvesActivity extends Activity implements AdapterView.OnItemClickListener{

	private String[] items = {
		"A Little Princess", "Harry Porter"
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.book_shelves);
		
		final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		// Adapter that shows a list of string resources
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.book_item, items);        
		ListView lst = (ListView)findViewById(R.id.list);
		lst.setAdapter(adapter);				
		lst.setOnItemClickListener(this);
	}

	public void onItemClick(AdapterView parent, View v, int position, long id) {    	
		Log.d("BookShelvesActivity", "Item: " + items[position]);
		Intent intent = new Intent();		
		ComponentName compName = new ComponentName("samse.app.ebook", "samse.app.ebook.BookViewerActivity");
		intent.setComponent(compName); 
		intent.putExtra("path", "sdcard/ebook/example.txt");
		intent.putExtra("Title", items[position]);
		intent.putExtra("JumpTo", 1);
		intent.setAction("android.intent.action.MAIN");
		startActivity(intent);
    }
	
}
